#include <stdio.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

int main(){
    char buf[1024] = {0};
    int ret_fd = open("./read.txt", O_RDONLY); 
    if(ret_fd < 0){printf("文件打开失败！\n");}
    else{printf("文件打开成功！\n");}

    //读取文件内容
    int ret_read = read(ret_fd, buf, sizeof(buf));
    printf("读取文件成功！\n");
    close(ret_fd);

    //将读取到的内容写到文件里面
    ret_fd = open("./write.txt", O_WRONLY | O_TRUNC | O_CREAT, 0644);
    write(ret_fd, buf, sizeof(buf));
    printf("写入文件成功！\n");

    close(ret_fd);
    return 0;
}
